home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
rptgen
/
rptmain.bas
< prev
Wrap
BASIC Source File
|
1995-05-09
|
16KB
|
492 lines
Function RptCreate (rtitle$, numcols%, textcols%, nrows%, thinbars%, thickbars%, tit1$, tit2$, foot1$, foot2$)
' function to create a new report
' Graham Hobson (72506,3410) Created: 24th September, 1991
'
' Parameters:
' rtitle$ is the caption for the report form
' numcols is the number of numeric columns
' textcols is the number of text columns
' nrows is the maximum number of rows for the report (may be larger than one page)
' thinbars number (n) says to draw a thin line on the printed report every n rows
' use zero if you don't want any thinbars
' thickbars, ditto but with a thicker line
' tit1 is the main title
' tit2 is the secondary title
' foot1 is the first footnote
' foot2 is the second footnote
On Error GoTo memerror
ncols% = numcols% + textcols%
If ncols% < 1 Then MsgBox "Error: there must be one or more columns", 16, "RptCreate"
ReDim RptCol(1 To ncols%) As RptCol_Type
If numcols% > 0 Then ReDim RptNumData(1 To numcols%, 1 To nrows%) As Single
If textcols% > 0 Then ReDim RptTextData(1 To textcols%, 1 To nrows%) As String
ReDim RptSortTop(10) As Integer
ReDim RptSortBottom(10) As Integer
RptForm.Show
RptForm.caption = rtitle$
RptForm.Refresh
rpt.name = rtitle$
rpt.headerheight = 600
rpt.defrowheight = 225
rpt.thinbars = thinbars%
rpt.thickbars = thickbars%
If rpt.thinbars = 0 Then rpt.thinbars = 9999
If rpt.thickbars = 0 Then rpt.thickbars = 9999
RptForm.LAB_title1.caption = tit1$
RptForm.LAB_title2.caption = tit2$
RptForm.LAB_footnote1.caption = foot1$
RptForm.LAB_footnote2.caption = foot2$
rpt.cols = ncols%
rpt.numcols = numcols%
rpt.textcols = textcols%
rpt.rows = nrows%
' work out number of rows per page
rpt.rowsperpage = (Printer.height - 1750 - 2000 - rpt.headerheight) / (rpt.defrowheight + 15)
rpt.pages = (rpt.rows \ rpt.rowsperpage) + 1
RptForm.grid1.cols = rpt.cols
RptForm.grid1.rows = rpt.rowsperpage + 1
rpt.currentnumcol = 0
rpt.currenttextcol = 0
RptCreate = 0
Exit Function
memerror:
MsgBox "Error: report too large!", 16, "RptCreate"
RptCreate = -1
End Function
Sub RptDefineColumn (Rhnd%, colno%, ctype$, ctitle$, cwidth%, calign%, cfmt$, bar%)
' routine to create a new column
' Rhnd is a report handle (not currently used)
' colno is the column number (from 1 to max)
' ctype is the datatype: A for text and 9 for numeric
' ctitle is the column title
' cwidth is the default width in twips
' calign is the alignment: 0 = left, 1 = centred, 2 = right
' cfmt is a standard VB format string used to format each cell value
' bar is a flag indicating if a vertical bar should be drawn on the printed report
' 0 (FALSE) = no, -1 (TRUE) = yes
If colno% < 1 Or colno% > rpt.cols Then MsgBox "invalid column number", 16, "RptDefineColumn"
RptCol(colno%).fmt = cfmt$
RptCol(colno%).bar = bar%
RptCol(colno%).datatype = ctype$
RptCol(colno%).ctitle = ctitle$
RptCol(colno%).cwidth = cwidth%
RptCol(colno%).calign = calign%
' set pointer to data column
If ctype$ = "9" Then
If rpt.currentnumcol < rpt.numcols Then
rpt.currentnumcol = rpt.currentnumcol + 1
RptCol(colno%).ptr = rpt.currentnumcol
Else
MsgBox "too many numeric columns", 16, "RptDefineColumn"
End If
ElseIf ctype$ = "A" Then
If rpt.currenttextcol < rpt.textcols Then
rpt.currenttextcol = rpt.currenttextcol + 1
RptCol(colno%).ptr = rpt.currenttextcol
Else
MsgBox "too many text columns", 16, "RptDefineColumn"
End If
Else
MsgBox "Invalid datatype", 16, "RptDefineColumn"
End If
If cwidth% <= 0 Then MsgBox "invalid column width", 16, "RptDefineColumn"
RptForm.grid1.col = colno% - 1
RptForm.grid1.row = 0
RptForm.grid1.text = ctitle$
RptForm.grid1.colwidth = cwidth%
RptForm.grid1.rowheight = rpt.headerheight
RptForm.grid1.colalignment = calign%
' set sort menu item
If colno% > 1 Then Load RptForm.MSort(colno%)
RptForm.MSort(colno%).caption = "&" + Format$(colno%) + "." + ctitle$
End Sub
Sub RptDelete (Rhnd%)
Unload RptForm
End Sub
Sub RptNewPage (Rhnd%, page%)
' procedure to display specified page of a report
' report handle is ignored currently
If page% > rpt.pages Or page% < 1 Then MsgBox "invalid page number", 16, "RptNewPage"
Screen.MousePointer = 11
'-----------
' clear grid control
x% = RptForm.grid1.col
y% = RptForm.grid1.row
RptForm.grid1.Selstartrow = 1
RptForm.grid1.SelStartcol = 0
RptForm.grid1.Selendrow = RptForm.grid1.rows - 1
RptForm.grid1.Selendcol = RptForm.grid1.cols - 1
RptForm.grid1.clip = ""
RptForm.grid1.Selstartrow = 1
RptForm.grid1.SelStartcol = 1
RptForm.grid1.Selendrow = 1
RptForm.grid1.Selendcol = 1
'-----------
rpt.page = page% ' set current page number
RptForm.caption = RTrim$(rpt.name) + " - (Page " + Format$(rpt.page) + " of " + Format$(rpt.pages) + ")"
' populate grid with data for current page
For y% = ((page% - 1) * rpt.rowsperpage) + 1 To (page% * rpt.rowsperpage)
If y% > rpt.rows Then Exit For
For x% = 1 To rpt.cols
RptForm.grid1.row = y% Mod rpt.rowsperpage
If RptForm.grid1.row = 0 Then RptForm.grid1.row = rpt.rowsperpage
RptForm.grid1.col = x% - 1
If RptCol(x%).datatype = "9" Then
RptForm.grid1.text = Format$(RptNumData(RptCol(x%).ptr, y%), RTrim$(RptCol(x%).fmt) + " ")
Else
RptForm.grid1.text = RptTextData(RptCol(x%).ptr, y%)
End If
Next
Next
RptForm.Refresh
Screen.MousePointer = 0
End Sub
Sub RptPrint (Rhnd%)
' prints current report page. Report handle is currently ignored
Screen.MousePointer = 11
RptForm.TXT_status.visible = -1
RptForm.TXT_status.text = "Printing page " + Format$(rpt.page) + " of " + Format$(rpt.pages)
Printer.fontname = Printer.fonts(3) ' universe on an HP laserjet
'--------------------------------------------------------
' get max width and height of grid by looping thru columns and rows
'--------------------------------------------------------
maxwidth% = 0
maxheight% = rpt.headerheight + 15
For y% = 1 To rpt.rowsperpage
RptForm.grid1.row = y%
If RptForm.grid1.text = "" Then Exit For
maxheight% = maxheight% + rpt.defrowheight + 15
Next
For x% = 0 To rpt.cols - 1
RptForm.grid1.col = x%
maxwidth% = maxwidth% + RptForm.grid1.colwidth + 15
Next
'----------------------------
' date and pagenumber
'----------------------------
Printer.fontsize = 9
Printer.currentx = 550
Printer.currenty = 380
Printer.Print Format$(Now, "dd mmmm, yyyy");
Printer.currentx = Printer.width - Printer.TextWidth("Page " + Format$(rpt.page)) - 1300
Printer.Print "Page " + Format$(rpt.page)
'----------------------------
' main title
'----------------------------
Printer.fontbold = -1
Printer.fontsize = 16
Printer.currentx = ((Printer.width - Printer.TextWidth(RptForm.LAB_title1.caption)) / 2) - 400
Printer.currenty = 620
Printer.Print RptForm.LAB_title1.caption
'----------------------------
' second title
'----------------------------
Printer.fontbold = 0
Printer.fontsize = 12
Printer.currentx = ((Printer.width - Printer.TextWidth(RptForm.LAB_title2.caption)) / 2) - 400
Printer.currenty = 1100
Printer.Print RptForm.LAB_title2.caption
'----------------------------
' footnotes
'----------------------------
Printer.fontbold = 0
Printer.fontsize = 9
Printer.currentx = 550
Printer.currenty = Printer.height - 1600
Printer.Print RptForm.LAB_footnote1.caption
Printer.currentx = 550
Printer.currenty = Printer.height - 1200
Printer.Print RptForm.LAB_footnote2.caption
' draw grid
Printer.fontsize = 8.25
If (Printer.width - maxwidth%) > 800 Then
orgx% = ((Printer.width - maxwidth%) / 2) - 400 ' centred report
Else
orgx% = 400 ' won't fit so left justified
End If
orgy% = 1750
'--------------------------------------------------------
' draw outline of report table with shadows
'--------------------------------------------------------
Printer.currentx = orgx%
Printer.currenty = orgy%